package com.example.baijiebrower.update;

import android.app.Dialog;
import android.content.Context;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.baijiebrower.R;

/**
 * @ClassName UpdateDialog
 * @Author liufeng
 * @Date 2024/9/14
 * @email liufeng@szbaijie.cn
 * @Description
 */
public class UpdateDialog extends Dialog {

    private Context mContext;
    private String mUrl;
    private String mVersionName;
    private String mUpdateMessage;
    private TextView mTitle;
    private TextView updateMessage;
    private Button mUpdate;
    private Button mCancel;
    public UpdateDialog(@NonNull Context context , String url , String versionName , String updateMessage) {
        super(context);
        this.mContext = context;
        this.mUrl = url;
        this.mVersionName = versionName;
        this.mUpdateMessage = updateMessage;
        setContentView(R.layout.update_dialog);
        initDialog();
    }

    private void initDialog(){
        mTitle = findViewById(R.id.textView1);
        updateMessage = findViewById(R.id.updateMessage);
        mUpdate = findViewById(R.id.update);
        mCancel = findViewById(R.id.updateCancel);
        mTitle.setText(mContext.getString(R.string.Update_prompt,mVersionName));
        updateMessage.setText(mUpdateMessage);
        mCancel.setOnClickListener(v -> dismiss());
        mUpdate.setOnClickListener(v -> {
            UpdateLoad updateLoad = new UpdateLoad(mContext , mUrl);
            updateLoad.setCanceledOnTouchOutside(false);
            updateLoad.show();
            dismiss();
        });
    }
}
